<?php

namespace App\Http\Controllers\Manage;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;

use App\Model\Business;
use App\Model\Clue;
use App\Model\Demand;
use App\Model\Product;

class BusinessController extends Controller
{
    /**
     * 商机列表
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function businessList() {
        $business = Business::orderBy('rank','desc')->get();
        foreach ($business as $k => $value) {
            $dem = Demand::where('id',$value['demand_id'])->first();
            $business[$k]['product'] = $dem['product_id'];
            $business[$k]['description'] = $dem['description'];
        }
//        dump($business);
        return view('manage.business.businessList',['business'=>$business,'active1'=>3,'active2'=>1]);
    }

    /**
     * 启禁用商机
     * @return array
     */
    public function businessStatus() {
        $id = Input::get('id');
        $status = Input::get('status');
        if($status == 1) {
            $del = Business::where('id',$id)->update(['status'=>1]);
            $msg = '启用成功！';
        }else{
            $del = Business::where('id',$id)->update(['status'=>0]);
            $msg = '禁用成功！';
        }
        if(!$del){
            return [
                'code'=>101,
                'msg'=>'设置失败！'
            ];
        }
        return [
            'code'=>100,
            'msg'=>$msg
        ];
    }
}
